﻿#ifndef MEASUREDOTS2LINE_H
#define MEASUREDOTS2LINE_H

#include "MeasureElement.h"
namespace Qly {

class MeasureDataSet;

/**
 * @brief The MeasureDots2Line class 点到直线的距离
 *
 *         m_results_um[0] 存放的是第1个测点到直线的距离
 *         m_results_um[1] 存放的是第2个测点到直线的距离
 *         m_results_um[n] 存放的是第n+1个测点到直线的距离
 *         textTemplate 支持 @length_um, @length_mm, @length, @unit, @id, @pid 6 个关键字
 *         @pid 是当前对象的内部计数
 */
class MeasureDots2Line:public MeasureElement
{
    friend MeasureDataSet;
public:
    MeasureDots2Line(MeasureDataSet * parent = nullptr);
    QString name() Q_DECL_OVERRIDE {return u8"垂线距离";}
    int setPixelSize(double newPixelSize_um, int method) Q_DECL_OVERRIDE;
    bool isInTextBox(const QPointF & point) Q_DECL_OVERRIDE;
    void textMove(const QPointF & offset_pix, const QPointF & offset_um) Q_DECL_OVERRIDE;
private:

    int mouseLButtonPress(QPointF point_pix, QPointF point_um) Q_DECL_OVERRIDE;
    int mouseRButtonPress(QPointF point_pix, QPointF point_um) Q_DECL_OVERRIDE;
    int mouseLButtonRelease(QPointF point_pix, QPointF point_um) Q_DECL_OVERRIDE;
    int mouseMove(QPointF point_pix, QPointF point_um) Q_DECL_OVERRIDE;
    DeleteResult tryDelete(QPointF p) Q_DECL_OVERRIDE;
    void compute(void) Q_DECL_OVERRIDE; //计算图元的位置，还有长度结果
    void updateText(bool updatePosition = true) Q_DECL_OVERRIDE;
    void paint( QPainter &painter ) Q_DECL_OVERRIDE; //画方法
    QPointF endPoint(QPointF lineS, QPointF lineE, QPointF p);// 计算点到直线的垂足
    void resume(); // 接着添加数据
    QVector<TextBlock> m_textBlocks;

    QPointF m_tempPoint_pix[2];
    QPointF m_tempPoint_um[2];

    TextBlock * m_pTextBlock = nullptr;
    double m_angle;
};

}
#endif // MEASUREDOTS2LINE_H
